
/****************************************************************************/
/*Copyright (c) 2011, Florent DEVILLE.                                      */
/*All rights reserved.                                                      */
/*                                                                          */
/*Redistribution and use in source and binary forms, with or without        */
/*modification, are permitted provided that the following conditions        */
/*are met:                                                                  */
/*                                                                          */
/* - Redistributions of source code must retain the above copyright         */
/*notice, this list of conditions and the following disclaimer.             */
/* - Redistributions in binary form must reproduce the above                */
/*copyright notice, this list of conditions and the following               */
/*disclaimer in the documentation and/or other materials provided           */
/*with the distribution.                                                    */
/* - The names of its contributors cannot be used to endorse or promote     */
/*products derived from this software without specific prior written        */
/*permission.                                                               */
/* - The source code cannot be used for commercial purposes without         */ 
/*its contributors' permission.                                             */
/*                                                                          */
/*THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       */
/*"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT         */
/*LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS         */
/*FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE            */
/*COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,       */
/*INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,      */
/*BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;          */
/*LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER          */
/*CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT        */
/*LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN         */
/*ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE           */
/*POSSIBILITY OF SUCH DAMAGE.                                               */
/****************************************************************************/

#pragma once
#ifndef CPRIMPLAN_H
#define CPRIMPLAN_H

#include "RTIPrimitive.h"
#include "RTToolTypes.h"

namespace RT
{
	/*Infinite plan primitive*/
	class RTPrimPlan : public RTIPrimitive
	{
	private:
		/*Coefficient in the plan equation : Ax + By + Cz + D = 0*/
		F32 m_A, m_B, m_C, m_D; 

		/*A point in the plan used to solve the intersection equation*/
		RTPoint3f m_point;

		/*Primitive normal*/
		RTNormal3f m_normal;

		/*The three points used to define a plan*/
		RTVector3f m_p1, m_p2, m_p3; 

	public:
		/*Constructor*/
		RTPrimPlan(const RTPoint3f& p1, const RTPoint3f& p2, const RTPoint3f& p3);

		/*Destructor*/
		~RTPrimPlan();

		/*Calculate intersection between a ray and the plan*/
		bool intersect(const RTRay& ray, F32& dist, bool useGlobalCoordinates);

		/*Calculate the normal*/
		void computeNormal(const RTRay& ray, F32 dist, RTVector3f& normal)const;

		/*Check if the point is a point of the plan*/
		bool isInside(const RTVector3f& p)const;

	};
}
#endif